package com.ziyun.erp.modules.userRegisterSource.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.utils.Query;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;


import com.ziyun.erp.modules.userRegisterSource.dao.UserRegisterSourceDao;
import com.ziyun.erp.modules.userRegisterSource.entity.UserRegisterSourceEntity;
import com.ziyun.erp.modules.userRegisterSource.service.UserRegisterSourceService;


@Service("userRegisterSourceService")
public class UserRegisterSourceServiceImpl extends ServiceImpl<UserRegisterSourceDao, UserRegisterSourceEntity> implements UserRegisterSourceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<UserRegisterSourceEntity> page = new Page<>(Integer.parseInt(params.get("page").toString()),
                Integer.parseInt(params.get("limit").toString()) );
        page.setRecords(this.baseMapper.selectSourceList(page, params));
        return new PageUtils(page);
    }


    /*
     * 删除修改display
     */

    @Override
    public void deleteUpdate(String sourceId) {
        Map<String, Object> updateMap = new HashMap<>();
        updateMap.put("display", 1);
        baseMapper.updateByMap(updateMap, sourceId);
    }

    @Override
    public void updateByMap(UserRegisterSourceEntity userRegisterSource) {
        Map<String, Object> updateMap = new HashMap<>();
        updateMap.put("sourceName",userRegisterSource.getSourceName());
        updateMap.put("sourceKey",userRegisterSource.getSourceKey());
        updateMap.put("sourceUrl",userRegisterSource.getSourceUrl());
        updateMap.put("sendCoupon",userRegisterSource.getSendCoupon());
        updateMap.put("startTime",userRegisterSource.getStartTime());
        updateMap.put("endTime",userRegisterSource.getEndTime());
        updateMap.put("registerCouponIds",userRegisterSource.getRegisterCouponIds());
        updateMap.put("orderCouponIds",userRegisterSource.getOrderCouponIds());
        baseMapper.updateByMap(updateMap, userRegisterSource.getSourceId().toString());
    }

}
